package com.cast.web.controller;


import com.cast.domain.User;

import com.cast.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;




@Controller
@RequestMapping("/user")
@ResponseBody
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public List<User> findAall() {
        List<User> users = userService.findAall();
        return users;
    }


    @RequestMapping("/addUser")
    public void addUser(String name, double money) {
        userService.addUser(name, money);
    }

    @RequestMapping("/deleteByName")
    public void deleteByName(String name) {
        userService.deleteByName(name);
    }

    @RequestMapping("/updateUser")
    public void updateUser(@RequestBody User user) {
        userService.updateUser(user);
    }

    @RequestMapping("/findByName")
    public User findByName(String name) {
        User user = userService.findByName(name);
        return user;
    }

    @RequestMapping("/findById")
    public User findByName(int id) {
        User user =  userService.findById(id);
        return  user;
    }

    @RequestMapping("/deleteById")
    public void deleteById(int id) {
        userService.deleteById(id);
    }

}
